# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# The jquery comboselect plugin: http://plugins.jquery.com/project/comboselect
# Jason Huck: http://devblog.jasonhuck.com/2008/04/25/jquery-combo-select-redux/
# Packaged as a tw.jquery widget by Ciaran Farrell <cfarrell1980@gmail.com>

from tw.api import Widget, JSLink, CSSLink, js_function, js_callback
from tw.forms.fields import TableForm
from tw.jquery.base import *

jQuery = js_function('$')

jquery_tools_js = JSLink(
        filename='static/javascript/jquery.jeditable.mini.js',
        javascript=[jquery_js],
        modname=__name__)

#jquery_tabs_css = CSSLink(
#        filename='static/css/tabs.css',
#        modname=__name__)

class Jeditable(Widget):
    javascript=[jquery_tools_js]
#    css=[jquery_tabs_css]
    #template = "genshi:tw.jquery.templates.dummy"
    template = """
    """
    action=""

    def __init__(self,id=None,parent=None,children=[],**kw):
        self.action = kw['action']
        super(Jeditable,self).__init__(id,parent,children,**kw)

    def update_params(self,d):
        super(Jeditable,self).update_params(d)
        print self.action
	self.add_call("$(function(){$('.edit').editable('%s',{style:'inherit',submit:'Save',cancel:'Cancel'})});"%self.action)
	self.add_call("$(function(){$('.edit_textile').editable('/record/update/',{style:'width:70%',submit:'Save',cancel:'Cancel'})});")
